import type { LoginResponseData, UserInfoData } from '@/api/user/type'

const TOEKN = 'TOKEN'

export const SET_TOKEN = (token: LoginResponseData) => {
  DELETE_TOKEN()
  localStorage.setItem(TOEKN, JSON.stringify(token))
}

export const GET_TOKEN = (): LoginResponseData => {
  return JSON.parse(localStorage.getItem(TOEKN) ?? '{}') as LoginResponseData
}

export const DELETE_TOKEN = () => {
  localStorage.removeItem(TOEKN)
}

const USER_INFO = 'USER_INFO'

export const SET_USERINFO = (userInfo: UserInfoData) => {
  DELETE_USERINFO()
  localStorage.setItem(USER_INFO, JSON.stringify(userInfo))
}

export const GET_USERINFO = (): UserInfoData => {
  console.log('GET_USERINFO==>', localStorage.getItem(USER_INFO))
  return JSON.parse(localStorage.getItem(USER_INFO) ?? '{}') as UserInfoData
}

export const DELETE_USERINFO = () => {
  localStorage.removeItem(USER_INFO)
}
